﻿using RBOSS.Business.Checkout;
using RBOSS.Business.Views;

namespace RBOSS.Business.Presenters
{
    public class ShippingPresenter
    {
        private IShippingView _view;
        private readonly ICheckoutSubsystem _checkoutSubsystem;
        public ShippingPresenter(IShippingView view)
        {
            _view = view;
            _checkoutSubsystem = new CheckoutSubsystem();
            _view.ShowEmail(_checkoutSubsystem.IsGuest());
          
        }

        public void PopulateInformation()
        {
            var shippingInfo = _checkoutSubsystem.GetShippingInfo();
            if (shippingInfo != null)
            {
                _view.Address1 = shippingInfo.Address1;
                _view.Address2 = shippingInfo.Address2;
                _view.City = shippingInfo.City;
                _view.Country = shippingInfo.Country;
                _view.FullName = shippingInfo.FullName;
                _view.PhoneNumber = shippingInfo.PhoneNumber;
                _view.State = shippingInfo.State;
                _view.Zip = shippingInfo.Zip;
                _view.Email = _checkoutSubsystem.GetCustomer().CustomerDetails.Email;
            }
        }

        public void CopyBillingAddress()
        {
            IBilling billing = _checkoutSubsystem.GetBillingInfo();
            _view.Address1 = billing.Address1;
            _view.Address2 = billing.Address2;
            _view.City = billing.City;
            _view.Country = billing.City;
            _view.FullName = billing.NameOnCard;
            _view.State = billing.State;
            _view.Zip = billing.Zip;

        }

        public void SaveBillingInformation()
        {
            var shipping = new Shipping
            {
                Address1 = _view.Address1,
                Address2 = _view.Address2,
                City = _view.City,
                Country = _view.Country,
                State = _view.State,
                FullName = _view.FullName,
                PhoneNumber = _view.PhoneNumber,
                Zip = _view.Zip

            };
            _checkoutSubsystem.SaveShippingInfo(shipping);
            if (_checkoutSubsystem.IsGuest())
            {
                _checkoutSubsystem.GetCustomer().CustomerDetails.Email = _view.Email;
            }
        }
    }
}
